import store from '../store/index';
export default {
	// BASEURI: 'http://33459a4a.r11.vip.cpolar.cn/api/',
	// ESURI: 'http://33459a4a.r11.vip.cpolar.cn/api/',
	// BASEURI: 'http://localhost:8088/api/',
	// ESURI: 'http://localhost:8088/api/',
	BASEURI: 'http://yzadmin.jxoem.com/api/',
	ESURI: 'http://yzadmin.jxoem.com/api/',
	// BASEURI: 'http://xfadmin.jxoem.com/api/',
	// ESURI: 'http://xfadmin.jxoem.com/api/',
	
	
	STORE_ID : 131,
	index: {
		home: 'single/home/content',
		appletLogin_by_weixin: 'applet/login_by_weixin',
		logs: 'single/home/logs', //  记录日志
		userInfo: 'single/home/userInfo', //  用户信息
		getExamroomDistribution: 'dms/examroomdistribution/get', // 考场分布
		getCorporateCulture: 'dms/corporateculture/get', //  企业文化
		getWebnet: 'dms/webnet/get', //  官网
		getDynamic: 'dms/dynamic/list', //  动态
	},
	gateway:{
		getGateways:'gatewayDevice/h5List',
		operate:'gatewayDevice/h5Operate'
	},
	member: {
		updateMemberPhone: 'member/updateMemberPhone' ,//更新会员手机号
		weixinLogin:'member/weixinLogin',
		create: 'member/createMember',
		getMemberByPhone: 'member/getMemberByPhone'
	},
	user: {
		userLogin:'dms/user/login'
	},
	qsg:{
		roomList:'dms/room/list',
		getData:'dms/report/getData',
		getReport:'dms/report/indexdata',
		reportdetail:'dms/report/reportdetailgroupbypaytype',
		getDeviceInfo:'dms/device/getDeviceStatus',
		memberdetail:'qsg/memberstore/memberdetail',
		getDevices:'dms/device/list',
		getDeviceById:'dms/getDeviceById',
		createDevice:'dms/device/create',
		getDeviceMeal:'dms/device/getDeviceMealH5',
		openDoor:'dms/task/openDoor',
		openDoorTmp:'dms/task/openDoorTmp',
		openByTime:'dms/task/openByTime',
		closeDoor:'dms/task/closeDoor',
		deleteBind:'dms/deleteBind',
		updateMeal:'dms/update/',
		reportlist:'dms/report/list',
		memberstore:'qsg/memberstore/list',
		listcert:'certificate/listadmin',
		sendcert:'certificate/sendcert',
		deleteCert:'certificate/delete',
		getStore:'qsg/store/getStoreById',
		updateStore:'qsg/store/updateStore',
		updateRoom:'dms/room/update',
		clearOrder:'dms/room/clearOrder',
		listRechargeH5:'dms/recharge/listH5',
		deleteRecharge:'dms/recharge/delete',
		createRecharge:'dms/recharge/create',
		getMealById:'dms/recharge/getMealById',
		openDamen:'dms/task/openDamen',
		addJifen:'dms/integral/addJifen',
		getIntegralDetail:'dms/integral/getIntegralDetail',
		updateRoomStatus:'dms/room/updateRoomStatus',
		controlAir:'dms/task/controlAir',
		deletedevice:'dms/deletedevice',
		getTop10Users:'costduration/getTop10Users'
	},
	meal: {
		getMeals: 'dms/meal/list',
		getMealById: 'dms/meal/getMealById',
		create:'dms/meal/create',
		deleteMeal:'dms/meal/delete',
		getMeituanMeal:'dms/meal/getMeituanMeal'
	},
	item: {
		getAllItem: 'dms/item/getAllItem'
	},
	order: {
		getOrderDetail:'order/getOrderDetail',
		createOrder: 'order/generateDriverOrderByAdmin',
		driverOrderList: 'single/oms/driverorder/list', // 查询驾校订单列表
		coachOrderList: 'single/oms/coachOrderList/storelist', // 查询教练订单列表
		listAdmin: 'single/oms/coachOrderList/listAdmin', 
		listByMember: 'single/oms/coachOrderList/listByMember', 
		agreeCannelOrder:'order/agreeCannelOrder',
		refuseCannelOrder:'order/refuseCannelOrder',
		deleteOrder:'order/deleteOrderFromBack',
		checkIsIntersect:'order/checkIsIntersectByAdmin',
	},
	contract:{
		upload:'contract/upload',
		setGraph:'contract/setGraph',
		getMyGraph:'contract/getMyGraph',
		generatgeContract:'contract/generatgeContract'
	},
	/**
	 * 封装请求（async await 封装uni.request）
	 * method	   post/get
	 * endpoint    接口方法名
	 * data		   所需传递参数
	 * load		   是否需要loading
	 */
	async apiCall(method, endpoint, data, load) {
		if (load) {
			uni.showLoading({
				title: '请稍候',
				mask: true
			});
		}
		let fullurl = this.BASEURI + endpoint;
		let Authorization;
		let storeId = data.storeId;
		console.log(data)
		if(typeof storeId == 'undefined'){
			storeId = this.STORE_ID;
		}
		if (`${store.state.userInfo}`) {
			console.log(`${store.state.userInfo.id}`)
			let mid = `${store.state.userInfo.userInfo.id}`;
			if (mid) {
				data.memberId = mid;
				Authorization = `${store.state.userInfo.tokenHead}${store.state.userInfo.token}`;
			}
		}
		// var contentType = 'application/x-www-form-urlencoded';
			var contentType = 'application/json;charset=UTF-8';
		if (endpoint.indexOf('login') != -1) {
			//	contentType = 'application/json';
		}
		console.log(endpoint);
		let [error, res] = await uni.request({
			url: fullurl,
			data: data,
			method: method,
			header: {
				'storeid': storeId,
				//'Content-Type': 'application/x-www-form-urlencoded',
				'content-type': contentType,
				'Authorization': Authorization || ''
			},
		});
		if (load) {
			uni.hideLoading();
		}
		// console.log(res);
		if (res.data.msg == 'User token expired!') {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.msg == '请先登录' || res.data.code == 100) {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.code == 200) {
			return res.data.data;
		} else {
			console.log(res.data);
			if (res.data && res.data.msg) {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
				//this.$api.msg(res.data.msg);
			}

		}
	},
	/**
	 * 封装请求（async await 封装uni.request）
	 * method	   post/get
	 * endpoint    接口方法名
	 * data		   所需传递参数
	 * load		   是否需要loading
	 */
	async apiCallJson(method, endpoint, data, load) {
		if (!load) {
			uni.showLoading({
				title: '请稍候',
				mask: true
			});
		}
		let fullurl = this.BASEURI + endpoint;
		let Authorization;
		let storeId = 1;
		if (`${store.state.userInfo}`) {
			let mid = `${store.state.userInfo.userInfo.id}`;
			//storeId = `${store.state.userInfo.userInfo.storeId}`;
			if (mid) {
				data.memberId = mid;
				Authorization = `${store.state.userInfo.tokenHead}${store.state.userInfo.token}`;
			}
		}
		var contentType = 'application/json;charset=UTF-8';

		if (endpoint.indexOf('login') != -1) {
			//	contentType = 'application/json';
		}
		console.log(endpoint);
		let [error, res] = await uni.request({
			url: fullurl,
			data: data,
			method: method,
			header: {
				'storeid': storeId,
				//'Content-Type': 'application/x-www-form-urlencoded',
				'content-type': contentType,
				'Authorization': Authorization || ''
			},
		});
		if (!load) {
			uni.hideLoading();
		}
		if (res.data.message == 'User token expired!') {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		if (res.data.message == '请先登录' || res.data.code == 100) {
			uni.showToast({
				title: '请先登录',
				icon: 'none'
			});
			uni.navigateTo({
				url: `/pages/public/login`
			})
		}
		return res;
	}
}
